package com.cloudwise.controller;

import com.cloudwise.entity.Userinfo;
import com.cloudwise.service.UserinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author ：Teacher陈
 * @date ：Created in 2020/12/14 11:07
 * @description：测试
 * @modified By：
 * @version: 1
 */
@Controller
public class HelloController {
    @Autowired
    private UserinfoService userinfoService;
    /**
     * RequestMapping 默认接收所有类型的http请求
     * @RequestMapping+,method = RequestMethod.GET====>@Getmapping
     * @return
     */
/*    @RequestMapping(value = "toHelloPage" ,method = RequestMethod.GET)
    public String toHelloPage(){
        return "hello";
    }*/
    @GetMapping(value = "toHelloPage")
    public String toHelloPage(){
        return "hello";
    }
    @GetMapping(value = "toThymeleaf")
    public String toThymeleaf(){
        return "thymeleaf/xxx";
    }
/*    @GetMapping(value = "testMv")
    public ModelAndView testMv(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("username","chenjian");
        List<Userinfo> userinfoList = userinfoService.queryAllByLimit(0, 10);
        mv.addObject("userinfoList",userinfoList);
        mv.setViewName("thymeleaf/yyy");
        return mv;
    }*/
    @GetMapping(value = "testMv")
    public String  testMv(HttpServletRequest request){
      /*  ModelAndView mv = new ModelAndView();
        mv.addObject("username","chenjian");
        List<Userinfo> userinfoList = userinfoService.queryAllByLimit(0, 10);
        mv.addObject("userinfoList",userinfoList);
        mv.setViewName("thymeleaf/yyy");*/
        request.setAttribute("username","zhangsan");
        List<Userinfo> userinfoList = userinfoService.queryAllByLimit(0, 5);
        request.setAttribute("userinfoList",userinfoList);
        return "thymeleaf/yyy";
    }
}
